import prompt from '@system.prompt';
import router from '@system.router';
export default {
    data: {
        title: "",
        localtionX:"",
        localtionY:"",
        test:"",
        test1:"",
        click:"",
        media:"",
        port:"",
        upAnimation:"",
        downAnimation:"",
        leftAnimation:"",
        rightAnimation:"",
        textAnimation:"",
        model:"",
        controlDta:"",
        armStatus:""
    },
    onInit() {
        this.title = this.$t('strings.world');
        this.test="OpenHarmony";
        this.media="true";
    },
    onShow(){
        var options = {
            duration: 500,
            easing: 'friction',
            delay: 10,
            fill: 'forwards',
            iterations: 1,
            direction: 'normal',
        };
        var frames = [
            {transform: {translate: '-0px 20px'}, opacity: 0.1, offset: 0.0},
            {transform: {translate: '-0px -0px'}, opacity: 1.0, offset: 1.0}
        ];
        this.upAnimation = this.$element('upName').animate(frames, options);
        var options = {
            duration: 500,
            easing: 'friction',
            delay: 10,
            fill: 'forwards',
            iterations: 1,
            direction: 'normal',
        };
        var frames = [
            {transform: {translate: '-0px -20px'}, opacity: 0.1, offset: 0.0},
            {transform: {translate: '-0px -0px'}, opacity: 1.0, offset: 1.0}
        ];
        this.downAnimation = this.$element('downName').animate(frames, options);
        var options = {
            duration: 500,
            easing: 'friction',
            delay: 10,
            fill: 'forwards',
            iterations: 1,
            direction: 'normal',
        };
        var frames = [
            {transform: {translate: '20px -0px'}, opacity: 0.1, offset: 0.0},
            {transform: {translate: '-0px -0px'}, opacity: 1.0, offset: 1.0}
        ];
        this.leftAnimation = this.$element('leftName').animate(frames, options);
        var options = {
            duration: 500,
            easing: 'friction',
            delay: 10,
            fill: 'forwards',
            iterations: 1,
            direction: 'normal',
        };
        var frames = [
            {transform: {translate: '-20px -0px'}, opacity: 0.1, offset: 0.0},
            {transform: {translate: '-0px -0px'}, opacity: 1.0, offset: 1.0}
        ];
        this.rightAnimation = this.$element('rightName').animate(frames, options);
        var options = {
            duration: 1500,
            easing:'ease-in',
            delay:5,
            fill: 'forwards',
            direction:'alternate',
            iterations:1,
        };
        // @ts-ignore
        var frames = [
            {
                transform: {
                    translate: '50px -0px'
                },
                opacity: 0.1,
                offset: 0.0,
                width: 200,
                height: 200,
            },
            {
                transform: {
                    translate: '110px 0px'
                },
                opacity: 1.0,
                offset: 1.0,
                width: 300,
                height: 300,
            }
        ];
        this.textAnimation = this.$element('textAnimate').animate(frames, options);
    },
    upClick:async function(){
        console.log("upclick");
        this.model="自动赛";
        this.test="前进";
        this.controlDta="1";
        try {
            var action = this.initAction2(1012,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            //this.showToast(result);
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
        this.upAnimation.play();
    },
    upClick2:async function(){
        console.log("upclick");
        this.model="自动赛";
        this.test="加速前进";
        this.controlDta="111";
        try {
            var action = this.initAction2(1012,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            //this.showToast(result);
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
        this.upAnimation.play();
    },
    leftClick:async function(){
        console.log("leftclick")
        this.model="自动赛";
        this.test="左转";
        this.controlDta="3";
        try {
            var action = this.initAction2(1012,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
        this.leftAnimation.play();

    },
    leftClick2:async function(){
        console.log("leftclick")
        this.model="自动赛";
        this.test="加速左转";
        this.controlDta="311";
        try {
            var action = this.initAction2(1012,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
        this.leftAnimation.play();

    },
    rightClick:async function(){
        console.log("rightclick")
        this.model="自动赛";
        this.test="右转";
        this.controlDta="4";
        try {
            var action = this.initAction2(1012,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
        this.rightAnimation.play();
    },
    rightClick2:async function(){
        console.log("rightclick")
        this.model="自动赛";
        this.test="加速右转";
        this.controlDta="411";
        try {
            var action = this.initAction2(1012,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
        this.rightAnimation.play();
    },
    downClick:async function(){
        console.log("downclick")
        this.model="自动赛";
        this.test="后退";
        this.controlDta="2";
        try {
            var action = this.initAction2(1012,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
        this.downAnimation.play();
    },
    downClick2:async function(){
        console.log("downclick")
        this.model="自动赛";
        this.test="加速后退";
        this.controlDta="211";
        try {
            var action = this.initAction2(1012,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
        this.downAnimation.play();
    },
    wp0Click:async function() {
        console.log("wp0Click")
        this.controlDta="10";
        try {
            var action = this.initAction2(1002,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            if(this.test="OpenHarmony"){
                this.test="";
            }
            this.test1="发送起始点";
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }

    },
    wpAClick:async function() {
        console.log("wpAClick")
        this.controlDta="11";
        try {
            var action = this.initAction2(1002,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            if(this.test="OpenHarmony"){
                this.test="";
            }
            this.test1="发送必经点A";
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }

    },
    wpBClick:async function() {
        console.log("wpBClick")
        this.controlDta="12";
        try {
            var action = this.initAction2(1002,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            if(this.test="OpenHarmony"){
                this.test="";
            }
            this.test1="发送必经点B";
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
    },
    wpCClick:async function() {
        console.log("wpCClick")
        this.controlDta="13";
        try {
            var action = this.initAction2(1002,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            if(this.test="OpenHarmony"){
                this.test="";
            }
            this.test1="发送必经点C";
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
    },

    wpDClick:async function() {
        console.log("wpDClick")
        this.controlDta="14";
        try {
            var action = this.initAction2(1002,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            if(this.test="OpenHarmony"){
                this.test="";
            }
            this.test1="发送必经点D";
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
    },
    pickSpaceOneClick:async function() {
        console.log("pickSpaceOneClick")
        this.controlDta="21";
        try {
            var action = this.initAction2(1002,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            if(this.test="OpenHarmony"){
                this.test="";
            }
            this.test1="发送货物区1";
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
    },
    pickSpaceTwoClick:async function() {
        console.log("pickSpaceTwoClick")
        this.controlDta="22";
        try {
            var action = this.initAction2(1002,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            if(this.test="OpenHarmony"){
                this.test="";
            }
            this.test1="发送货物区2";
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
    },
    putSpaceOneClick:async function() {
        console.log("putSpaceOneClick")
        this.controlDta="31";
        try {
            var action = this.initAction2(1002,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            if(this.test="OpenHarmony"){
                this.test="";
            }
            this.test1="发送放置台大";
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
    },
    putSpaceTwoClick:async function() {
        console.log("putSpaceTwoClick")
        this.controlDta="32";
        try {
            var action = this.initAction2(1002,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            if(this.test="OpenHarmony"){
                this.test="";
            }
            this.test1="发送放置台中";
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
    },
    startClick:async function() {
        console.log("startClick")
        this.controlDta="start";
        try {
            var action = this.initAction2(1002,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            if(this.test="OpenHarmony"){
                this.test="";
            }
            this.test1="开始比赛";
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
    },
    startClick2:async function() {
        console.log("startClick")
        this.controlDta="1001";
        try {
            var action = this.initAction2(1002,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            if(this.test="OpenHarmony"){
                this.test="";
            }
            this.test1="复位按钮";
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
    },
    startClick3:async function() {
        console.log("startClick")
        this.controlDta="la";
        try {
            var action = this.initAction2(1002,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            if(this.test="OpenHarmony"){
                this.test="";
            }
            this.test1="右转小角度";
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
    },
    startClick4:async function() {
        console.log("startClick")
        this.controlDta="ra";
        try {
            var action = this.initAction2(1002,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            if(this.test="OpenHarmony"){
                this.test="";
            }
            this.test1="左转小角度";
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
    },
    startClick5:async function() {
        console.log("startClick")
        this.controlDta="fa";
        try {
            var action = this.initAction2(1002,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            if(this.test="OpenHarmony"){
                this.test="";
            }
            this.test1="小幅度前进";
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
    },
    startClick6:async function() {
        console.log("startClick")
        this.controlDta="ba";
        try {
            var action = this.initAction2(1002,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            if(this.test="OpenHarmony"){
                this.test="";
            }
            this.test1="小幅度后退";
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
    },
    touchEnd:async function(){
        this.controlDta="0";
        try {
            var action = this.initAction2(1002,this.controlDta);
            var result = await FeatureAbility.callAbility(action);
            console.info("onSend result = " + result);
            this.showToast("stop");
            this.test="OpenHarmony"
            this.test1="";
        } catch (pluginError) {
            console.error("getBatteryLevel : Plugin Error = " + pluginError);
        }
    },
    initConnectAction:function(code,ip,port){
        var actionData={};
        actionData.ip=ip;
        actionData.port=port;
        var action={};
        action.bundleName="com.example.tcpConnect";
        action.abilityName="tcpConnectTest";
        action.messageCode = code;
        action.data = actionData;
        action.abilityType = 1;
        action.syncOption = 0;
        return action;
    },
    initAction: function (code) {
        var actionData = {};
        var action = {};
        action.bundleName="com.example.tcpConnect";
        action.abilityName="tcpConnectTest";
        action.messageCode = code;
        action.data = actionData;
        action.abilityType = 1;
        action.syncOption = 0;
        return action;
    },

    initAction2: function (code,test) {
        var actionData = {};
        actionData.test = test;
        var action = {};
        action.bundleName="com.example.tcpConnect";
        action.abilityName="tcpConnectTest";
        action.messageCode = code;
        action.data = actionData;
        action.abilityType = 1;
        action.syncOption = 0;
        return action;
    },
   printData(msg){
        if(this.outcont != null || this.outcont != ""){
            this.outcont = msg + "\n" + this.outcont;
        } else {
            this.outcont = msg;
        }
    },
    showToast:function(msg){
        prompt.showToast({
            message:msg
        })
    }
}
